package ch.ethz.fcl.metrobuzz.render;

import org.lwjgl.opengl.GL11;

import ch.ethz.fcl.metrobuzz.MBContainer;
import ch.ethz.fcl.metrobuzz.MBProperty;
import ch.ethz.fcl.metrobuzz.data.MBData;
import ch.ethz.fcl.metrobuzz.render.accessbility.AccessibilityRender;
import ch.ethz.fcl.metrobuzz.render.interchange.InterchangeRender;
import ch.ethz.fcl.metrobuzz.render.od.ODRender;

public class MBRenderer {
	private MBContainer container;

	// general map visualization
	protected MapAttributesRender mapAttributes;

	// interchange visualization
	private InterchangeRender interchangeRender;

	// accessibility visualization
	private AccessibilityRender accessRender;

	// specific-link origin-destination visualization
	private ODRender odRender;

	public MBRenderer(MBContainer container) {
		this.container = container;
		container.setRender(this);

		init();
	}

	private void init() {
		mapAttributes = new MapAttributesRender(container);

		if (MBProperty.MRT || MBProperty.REGIONS)
			interchangeRender = new InterchangeRender(container);

		if (MBProperty.ACCESSIBILITY)
			accessRender = new AccessibilityRender(container);

		if (MBProperty.OD)
			odRender = new ODRender(container);
	}

	public void render() {
		// clear previous buffers
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

		if (MBProperty.ACCESSIBILITY) {
			accessRender.render();
		}

		if (MBProperty.MRT || MBProperty.REGIONS)
			interchangeRender.update();

		if (MBProperty.OD)
			odRender.update();

		// mapAttributes.render();
		// MBViewer.newUpdate = false;
	}

	public InterchangeRender getInterchangeRender() {
		return interchangeRender;
	}

	public AccessibilityRender getAccessibilityRender() {
		return accessRender;
	}

	public ODRender getODRender() {
		return odRender;
	}

	public void reset() {
		MBData.startTime = 8 * 4;
		MBData.period = 1;
		interchangeRender.reset();
	}

	public MBContainer getContainer() {
		return container;
	}
}
